package jjn.daily;

/**
 * @author Jiang Jining
 * @since 2023-09-15 23:43
 */
public class Lcp50 {
    public int giveGem(int[] gem, int[][] operations) {
        for (int[] operation : operations) {
            int index = operation[0];
            int taken = operation[1];
            int half = gem[index] / 2;
            gem[index] -= half;
            gem[taken] += half;
        }
        int max = gem[0], min = gem[0];
        for (int num : gem) {
            max = Math.max(num, max);
            min = Math.min(num, min);
        }
        return max - min;
    }
}
